package com.icbc.digitalwallet.controller;


import com.icbc.digitalwallet.common.util.R;
import com.icbc.digitalwallet.pojo.entity.BankAccount;
import com.icbc.digitalwallet.service.BankAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 *  测试一下银行账户的增删改查
 * </p>
 *
 * @author tx
 * @since 2021-07-17
 */

@RestController
@RequestMapping("/bankAccount")
@Api(tags = "银行账户管理")
public class BankAccountController {
    @Autowired
    private BankAccountService accountService;

    /**
     * 查
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation("查找账户")
    public R findAll(){
        List<BankAccount> bankAccountList = accountService.list();
        return R.ok().data("bankAccountList",bankAccountList);
    }

    /**
     * 增
     */
    @PostMapping("/save")
    @ApiOperation("新增用户")
    public R saveAccount(@ApiParam("账户") @RequestBody BankAccount bankAccount){
        accountService.save(bankAccount);
        return R.ok().message("添加成功");
    }

    /**
     * 改
     * @param account
     */
    @PostMapping("/update")
    @ApiOperation("更新用户")
    public R update(@RequestBody BankAccount account){
        accountService.updateBankById(account);
        return R.ok().message("修改成功");
    }

    /**
     * 删除
     * @param id
     */
    @PostMapping("delete/{id}")
    @ApiOperation("删除用户")
    public R deleteById(@ApiParam("用户id") @PathVariable String id){
        accountService.removeById(id);
        return R.ok().message("删除成功");
    }

}

